

$(document).ready(function(){
    createCode();
});


var code ; 

function createCode()
{ 
    code = "";
    var codeLength = 4;
    var checkCode = document.getElementById("checkCode");
    var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');

    for(var i = 0;i < codeLength; i++ )
    {
        var charIndex = Math.floor(Math.random()*36);
        code +=selectChar[charIndex];
    }
        if(checkCode)
        {
            checkCode.className="code";
            checkCode.innerHTML = code;
        }
}





function txtName(){
    var regCode = /^[A-Z,a-z]+\w{3,19}$/;
    var q = document.getElementById("txtUserName");
    var name = document.getElementById("UserName").value;
        if(regCode.test(name) == false){
            q.innerHTML = "<p class='code1'>请输入4到20位字符，首位不能为数字!</p>";
            return false;
        }else{
            $.ajax({
                dataType: "text",
                   type: "post",
                   url: "check.do",
                   data: "username="+name,
                   success: function(msg){
                if(msg.trim() == "true"){
                        q.innerHTML = "<p class='code1'>用户名已存在!</p>";
                        return false;
                    }else{
                        q.innerHTML = "<p class='code2'>通过</p>";
                        return true;
                    }
                   }
                });
        }
}


function txtEmail(){
        var regCode =  /^([a-zA-Z0-9]+.*[a-zA-Z0-9]*)+@{1}(163|126|sina|google|qq)\.com$/;
        var q = document.getElementById("txtUserEmail");
        var name = document.getElementById("UserEmail").value;
        if(regCode.test(name) == false){
            q.innerHTML = "<p class='code1'>邮箱格式不正确</p>";
            return false;
        }else{
            q.innerHTML = "<p class='code2'>正确</p>"
            return true;
        }
}


function txtPwd(){
        var regCode =  /^(\w|\W){6,16}$/;
        var q = document.getElementById("txtUserPwd");
        var name = document.getElementById("UserPwd").value;
        
        if(regCode.test(name) == false){
            q.innerHTML = "<p class='code1'>密码必须6~16位</p>";
            return false;
        }else{
            q.innerHTML = "<p class='code2'>正确</p>";
            return true;
        }
}


function txtPass(){
        var q = document.getElementById("txtUserPass");
        var pass = document.getElementById("UserPass").value;
        var pwd = document.getElementById("UserPwd").value;
        if(pass == "" || pass == null){
            q.innerHTML = "<p class='code1'>密码必须6~16位</p>";
            return false;
        }else{
            if(pass == pwd){
                q.innerHTML = "<p class='code2'>正确</p>";
                return true;
            }else{
                q.innerHTML = "<p class='code1'>密码不一致</p>";
                return false;
            }
        }
}

function txtCode(){
    var q = document.getElementById("txtCode");
    var q1 = document.getElementById("inputCode").value;
        if(q1 != code){
            q.innerHTML = "<p class='code1'>验证码不正确</p>";
            return false;
        }else{
            q.innerHTML = "<p class='code2'>正确</p>";
            return true;
        }
}

function xyj()
{
    var q = document.getElementById("txtCheck");
    var box = document.getElementById("check");
    if(box.checked == true){
        if(txtName() == false | txtEmail() == false | txtPwd() == false | txtPass() == false | txtCode() == false){
            return false;
        }else{
            return true;
        }
    }else{
        q.innerHTML = "<p class='code3'>注册失败</p>";
        return false;
    }
 }

$(function(){
    $("#qq").click(function(){
        
    });
});

